import request from '@/api/request'
import g from "@/utils/utilFn";
export function getlist(param) {
    param = g.objEngraving({
        role_name: "",
        page: 1,
        limit: 20,
        filed: 'id',
        sort: 'ascending'
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/roles/getlist',
        method: 'POST',
        data
    })
}
export function getlist_all(param) {

    let data = new FormData()
    return request({
        url: '/roles/getlist_all',
        method: 'POST',
        data
    })
}

export function remove_by_id(id) {
    let data = new FormData()
    data.append("id", id || "");
    return request({
        url: '/roles/delete_by_id',
        method: 'POST',
        data
    })
}

export function update(param) {
    param = g.objEngraving({
        id: "",
        role_name: "",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/roles/update',
        method: 'POST',
        data
    })
}

export function notExistAdd(param) {
    param = g.objEngraving({
        role_name: "",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/roles/notExistAdd',
        method: 'POST',
        data
    })
}

export function getModuleIdByRole(param) {
    param = g.objEngraving({
        role_id: "0",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/roles/getModuleIdByRole',
        method: 'POST',
        data
    })
}

export function updateRoletModule(param) {
    param = g.objEngraving({
        role_id: "0",
        module_ids: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/roles/updateRoletModule',
        method: 'POST',
        data
    })
}